<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="stylesheet" href="../css/mui.min.css">
  <link href="../css/mui.picker.css" rel="stylesheet"/>
  <link href="../css/mui.poppicker.css" rel="stylesheet"/>
  <title>进货</title>
  <style>
    html {
      font-family: Roboto, Arial, "Noto Sans CJK SC", "Noto Sans CJK TC", "Pingfang SC", "Microsoft Yahei", "WenQuanYi Micro Hei", sans-serif;
    }

    body {
      overflow-x: hidden;
      background-color: #fff !important;
    }

    .mui-content {
      font-size: 13px;
      background-color: #fff;
    }

    .flex {
      display: flex;
      margin-top: 5px;
    }

    .flex-item {
      flex: 1;
    }

    .mui-select {
      width: 80%;
      margin-left: 10%;
      border: 1px solid #C0C0C0;
      border-radius: 6px;
      line-height: 24px;
      font-size: 14px;
      color: #ACACB4;
      text-indent: 6px;
      display: inline-block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .mui-select:before {
      top: 1px;
      right: 5px;
    }

    /**/
    .goodsName-box {
      flex: 5;
    }

    .goodsId-box,.barCode-box {
      flex: 5;
    }

    .mui-input-row input {
      height: 26px;
      line-height: 24px;
      font-size: 13px;
      margin-bottom: 0;
      width: 90%;
      margin-left: 5%;
      padding: 0 3px;
    }

    .mui-input-row .mui-input-clear ~ .mui-icon-clear {
      top: 3px;
    }

    .search-btn-box {
      flex: 3;
    }

    .search-btn {
      border: 1px solid transparent;
      background-color: #ff6800;
      color: #fff;
      height: 28px;
      line-height: 26px;
      text-align: center;
      width: 80%;
      margin-left: 10%;
      border-radius: 2px;
      font-size: 14px;
    }

    /**/
    .add-goods-type {
      margin-top: 2px;
      position: relative;
      height: 26px;
      line-height: 26px;
      vertical-align: middle;
      margin-bottom: 2px;
    }

    .add-goods-type img {
      margin-top: 2px;
      margin-left: 10px;
      margin-right: 5px;
    }

    .add-goods-type span {
      padding-bottom: 2px;
    }

    #radioOld {
      margin-left: 10px;
    }

    #radioNew {
      margin-left: 20px;
    }

    .redioYes {
      color: #FF9800;
    }

    .redioYes:before {
      content: '';
      display: inline-block;
      height: 16px;
      width: 16px;
      background-position: -1px 3px;
      background-size: 14px 14px;
      background-repeat: no-repeat;
      background-image: url('../images/radio (3).png');
    }

    .redioNo:before {
      content: '';
      display: inline-block;
      height: 16px;
      width: 16px;
      background-position: -1px 3px;
      background-size: 14px 14px;
      background-repeat: no-repeat;
      background-image: url('../images/radio (4).png');
    }

    /**/

    .purchase-link {
      float: right;
      margin-right: 10px;
      display: inline-block;
      background-color: #ff6800;
      color: #fff;
      width: 84px;
      text-align: center;
      padding: auto 10px;
      border-radius: 8px;
    }

    .purchase-link:active {
      background-color: #ef9a60;
    }

    /*列表*/

    .goods-list {
      list-style: none;
    }

    .bgGray {
      background-color: #F8F8F8;
    }

    .goods-each {
      padding: 5px 5px;
      position: relative;
    }

    .img-box {
      flex: 2;
      position: relative;
    }

    .img-box-title {
      flex: 2;
      text-align: center;
    }

    .img-box img {
      height: 70px;
      width: 70px;
      vertical-align: middle;
      text-align: center;
    }

    .img-box .id {
      position: absolute;
      bottom: 1px;
      width: 100%;
      background-color: rgba(52, 52, 52, .5);
      color: #FFFFFF;
      text-align: center;
      font-size: 13px;
    }

    .goods-info-box {
      flex: 4;
      font-size: 14px;
      line-height: 24px;
    }

    .number-title {
      flex: 4;
      text-align: center;
    }

    .goods-info-box div {
      margin-left: 5px;
    }

    .goods-op-box {
      flex: 3;
      position: relative;
      height: 100%;
    }

    .op-title {
      flex: 3;
      text-align: center;
    }

    .choose-icon {
      position: absolute;
      right: 35px;
      width: 22px;
    }

    .choose-btn {
      width: 70%;
      position: absolute;
      bottom: -70px;
      right: 5px;
      text-align: center;
    }

    .sure-choose-btn {
      background-color: #FF9800;
      border-color: #FF9800;
    }

    .sure-choose-btn:active {
      background-color: #ef9a60;
    }

    .cancel-choose-btn {
      background-color: #DBDBDB;
      border-color: #DBDBDB;
    }

    .cancel-choose-btn:active {
      background-color: #f1eded;
    }

    /*滚动区*/

    .mui-scroll-wrapper {
      top: 94px;
      bottom: 43px;
    }

    /*底部*/

    footer {
      height: 42px;
      line-height: 42px;
      background-color: #fff;
      position: absolute;
      bottom: 0;
      width: 100%;
      text-align: center;
      font-size: 15px;
      padding: 2px 0 4px;
    }

    footer:before {
      content: '';
      height: 1px;
      position: absolute;
      right: 0;
      bottom: 42px;
      width: 100%;
      transform: scaleY(.5);
      background-color: #acacb4;
    }

    .next-btn {
      background-color: #FF9800;
      color: #fff;
      width: 98%;
      margin: 0 auto;
    }

    .next-btn:active {
      background-color: #ff6600;
    }

    /*加载*/

    .mui-pull-bottom-pocket {
      visibility: visible;
    }

    .mui-pull-bottom-pocket .mui-pull-loading {
      visibility: visible;
    }

    /**/

    .no {
      text-align: center;
      font-size: 14px;
      line-height: 30px;
    }

    /**/
    .mui-popover {
      height: 100px;
    }

    .mui-popover .mui-scroll-wrapper {
      top: 0;
      bottom: 0;
      padding: 5px;
    }

    /**/
    .full-img {
      width: 50%;
    }

    #middlePopover {
      height: 260px;

    }
  </style>
</head>

<body>
<div class="mui-content">
  <div class="flex">
    <div class="flex-item">
        	<span id="select-tag" class="mui-select select-tag">
            	全部用途
          </span>
    </div>
    <div class="flex-item">
          <span id="selsct-type" class="mui-select selsct-type">
            	全部尺寸
          </span>
    </div>
  </div>
  <div style="margin-top: 0;" class="flex">
    <div class="goodsName-box">
      <div class="mui-input-row">
        <input type="text" class="mui-input-clear" placeholder="请输入名称">
      </div>
    </div>
    <div class="goodsId-box">
      <div class="mui-input-row">
        <input type="text" class="mui-input-clear" placeholder="请输入ID">
      </div>
    </div>
    <div class="barCode-box">
      <div class="mui-input-row">
        <input type="text" class="mui-input-clear" placeholder="请输入货号">
      </div>
    </div>
    <div class="search-btn-box">
      <div class="search-btn">
        查找
      </div>
    </div>
  </div>
  <!---->
  <div class="add-goods-type">
    <!--<img id='radioOld' src="../images/radio (3).png" alt="" /><span class="addOldGoods">追加货品</span>-->
    <!--<img id='radioNew' src="../images/radio (4).png" alt="" /><span class="addNewGoods">新添货品</span>-->
    <span id='radioOld' class="redioYes">追加货品</span>
    <span id='radioNew' class="redioNo">新添货品</span>
    <div class="purchase-link">本店进货单</div>
  </div>
  <!---->
  <div id="refreshContainer" class="mui-scroll-wrapper total-scroll-wrapper">
    <div class="mui-scroll">
      <ul class="goods-list mui-table-view mui-table-view-chevron">

      </ul>
      <!---->
      <script id="goodsLi" type="text/html">
        <div class="flex title-box">
          <div class="img-box-title">礼品</div>
          <div class="number-title">数量</div>
          <div class="op-title">操作</div>
        </div>
        <%if(list.length>0){%>
        <% for(var i=0; i
        <list.length; i++) {%>
        <%if(i%2===0){%>
        <li class="goods-each">
          <%}else {%>
        <li class="goods-each bgGray">
          <%}%>
          <div class="flex">
            <div class="img-box">
              <a href="#middlePopover"><img class="img-info" index="<%=i%>" src="<%=imgPath+list[i].wareGoods.cutImg%>"
                                            alt=""/></a>
              <div class="id"><%=list[i].wareGoods.wareGoodsId%></div>
            </div>
            <div class="goods-info-box">
              <div class="goods-name">
                <%=list[i].wareGoods.name%>
              </div>
              <div class="goods-id">总部库存：
                <%=list[i].wareGoodsAmount%>
              </div>
              <div class="goods-num">门店库存：
                <%=list[i].shopGoodsAmount.amount%>
              </div>
            </div>
            <% if(list[i].isChoose){%>
            <div class="goods-op-box">
              <img class="choose-icon" src="../images/choose.png" alt=""/>
              <button type="button" class="cancel-choose-btn mui-btn mui-btn-danger choose-btn " index="<%= i %>"
                      data-id="<%=list[i].wareGoods.wareGoodsId%>">取消选择
              </button>
            </div>
            <%} else {%>
            <% if(list[i].wareGoodsAmount>0){%>
            <div class="goods-op-box">
              <div class="sure-choose-btn mui-btn mui-btn-primary choose-btn" index="<%= i %>"
                   data-id="<%=list[i].wareGoods.wareGoodsId%>">选择
              </div>
            </div>
            <%}else{%>
            <div class="goods-op-box">
              <div class="sure-choose-btn mui-btn mui-btn-primary choose-btn " disabled index="<%= i %>"
                   data-id="<%=list[i].wareGoods.wareGoodsId%>">选择
              </div>
            </div>
            <%}%>
            <%}%>
          </div>
        </li>
        <%}%>
        <%}else{%>
        <p class="no">暂无数据</p>
        <%}%>
      </script>
      <!---->
      <!--加载中-->
      <div class="mui-pull-bottom-pocket">
        <div class="mui-pull">
        </div>
      </div>
      <!--加载中-->
    </div>
  </div>
</div>
<!--底部-->
<footer class="flex btn-box">
  <div class="next-btn">
    下一步
  </div>
</footer>
<!---->
<!--显示附加信息-->
<div id="middlePopover" class="mui-popover">
  <div class="mui-popover-arrow"></div>
  <div class="mui-scroll-wrapper">
    <div class="mui-scroll">
      <img class="full-img" src="" alt=""/>
      <p class="fullName">规格：<span></span></p>
      <p class="tags">用途：<span></span></p>
      <p class="score">积分：<span></span></p>
      <p class="message">备注：<span></span></p>
    </div>
  </div>
</div>
<!---->
</body>
<script src="../config.js"></script>
<script src="../js/template-native.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/mui.min.js"></script>
<script src="../js/mui.picker.js"></script>
<script src="../js/mui.poppicker.js"></script>
<script>
  (function ($, doc) {
    var types = [{
        value: '',
        text: '全部尺寸'
      }],
      tags = [{
        value: '',
        text: '全部用途'
      }],
      currentShopObj,
      getType = 1,
      params = {
        tagIds: [],
        pageNo: 1,
        goodsName: '',
        goodsId: '',
        barCode: '',
        type: '',
        shopId: '',
        isUpper: true,
        upperStyle: 4,
      },
      storeParams = {
        tagIds: [],
        pageNo: 1,
        goodsName: '',
        goodsId: '',
        barCode: '',
        type: '',
        shopId: '',
        isUpper: true,
        upperStyle: 4,
        checkShopHavent: true
      },
      pageList = [],
      storePageList = [],
      applyGoodsList = [],
      applyGoods = {
        apply: {
          applyId: '',
          applyStatus: 1,
          storeId: '',
          storeName: ''
        },
        applyGoodsList: []
      },
      applyId = '',
      isLoading = false,
      pageTatol1 = 0,
      pageTatol2 = 0
    $.init()
    $.plusReady(function () {
      receiveParams()
      getTag()
      getTypes()
      getGoods(params)
    })
    $.ready(function () {
      bindEvent()
    })
    //滚动
    $('.mui-scroll-wrapper').scroll({
      scrollY: true,
      bounce: true,
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006，
    });

    //设置加载状态
    function setLoading(type) {
      switch (type) {
        case 1:
          document.querySelector(".mui-pull").innerHTML = '<div class="mui-pull-loading mui-icon mui-spinner"></div>\
						<div class="mui-pull-caption">正在加载</div>'
          break
        case 2:
          document.querySelector(".mui-pull").innerHTML = '<div class="mui-pull-caption">没有更多</div>'
          break
        case 0:
          document.querySelector(".mui-pull").innerHTML = ''
          break
      }

    }

    function pullupRefresh() {
      mui('.mui-scroll-wrapper').scroll().reLayout();
      var that = this
      setTimeout(function () {
        that.endPullupToRefresh(true);
      }, 2000)
    }

    function receiveParams() {
      var self = plus.webview.currentWebview();
      currentShopObj = self.currentShopObj;
      params.shopId = self.currentShopObj.storeId
      params.storeName = self.currentShopObj.storeName
      storeParams.shopId = self.currentShopObj.storeId
      applyGoods.apply.storeId = self.currentShopObj.storeId
      applyGoods.apply.storeName = self.currentShopObj.storeName
    }

    function bindEvent() {
      //滚动监听
      document.querySelector('.total-scroll-wrapper').addEventListener('scrollend', function (e) {
        if (e.detail.y <= e.detail.maxScrollY) {
          if (getType === 1) {
            if (isLoading === false) {
              if (++params.pageNo <= pageTatol1) {
                ajaxGoods(params)
              } else {
                setLoading(2)
              }
            }
          } else {
            if (isLoading === false) {
              if (++storeParams.pageNo <= pageTatol2) {
                ajaxGoods(storeParams)
              } else {
                setLoading(2)
              }
            }
          }
        }
      });
      //          	监听
      window.addEventListener('delete', function (e) {
        applyGoods.applyGoodsList = e.detail.applyGoodsList
        applyGoods.apply.applyId = e.detail.applyId
        if (getType === 1) {
          setPage(pageList)
        } else {
          setPage(storePageList)
        }
      })
      //显示用途
      $('.goods-list').on('tap', '.img-info', function (e) {
        var ind = this.getAttribute('index')
        if (getType === 1) {
          var typeFullName = pageList[ind].typeFullName
          var tags = ''
          pageList[ind].tags.forEach(function (item) {
            tags += item.tagDescribe + ' '
          })
          var itScore = pageList[ind].wareGoods.score
          var imgSrc = pageList[ind].wareGoods.cutImg
          var message = pageList[ind].wareGoods.message
        } else if (getType === 2) {
          var typeFullName = storePageList[ind].typeFullName
          var tags = ''
          storePageList[ind].tags.forEach(function (item) {
            tags += item.tagDescribe + ' '
          })
          var itScore = storePageList[ind].wareGoods.score
          var imgSrc = storePageList[ind].wareGoods.cutImg
          var message = storePageList[ind].wareGoods.message
        }
        console.log(122312)
        setTimeout(function () {
          document.querySelector('.full-img').setAttribute('src', config.imgPath + imgSrc)
          document.querySelector(".fullName span").innerText = typeFullName
          document.querySelector(".tags span").innerText = tags
          document.querySelector(".score span").innerText = itScore
          document.querySelector('.message span').innerHTML = message
        }, 0)
      })
      //查找
      document.querySelector(".search-btn").addEventListener('tap', function () {
        if (getType === 1) {
          params.goodsId = document.querySelector(".goodsId-box input").value
          params.goodsName = document.querySelector(".goodsName-box input").value
          params.barCode = document.querySelector(".barCode-box input").value
          params.pageNo = 1
          pageList = []
          ajaxGoods(params)
        } else {
          storeParams.goodsId = document.querySelector(".goodsId-box input").value
          storeParams.goodsName = document.querySelector(".goodsName-box input").value
          storeParams.barCode = document.querySelector(".barCode-box input").value
          storeParams.pageNo = 1
          storePageList = []
          ajaxGoods(storeParams)
        }
        mui('.total-scroll-wrapper').scroll().scrollTo(0,0,100);
      })
      //跳转列表
      $('.add-goods-type').on('tap', '.purchase-link', function () {
        var titleText = currentShopObj.storeName + '-进货'
        $.openWindow({
          url: 'purchaseList.html',
          id: 'purchaseList',
          styles: {
            top: 0, //新页面顶部位置
            bottom: 0, //新页面底部位置
            titleNView: {
              titleText: titleText,
              titleColor: "#FFFFFF",
              titleSize: "17px",
              backgroundColor: "#FF6800",
              autoBackButton: true,
              buttons: [{
                float: "right",
                fontSize: "18px",
                fontSrc: "_www/fonts/iconfont.ttf", //wap2app内置字体文件
                text: "\ue602",
                onclick: function () {
                  var allPage = plus.webview.all()
                  var nowPage = plus.webview.getWebviewById('index')
                  for (var i = 0; i < allPage.length; i++) {
                    if (allPage[i].getURL() !== nowPage.getURL()) {
                      plus.webview.close(allPage[i]);
                    }
                  }
                }
              }],
              splitLine: {
                color: "#CCCCCC",
                height: "1px"
              }
            }
          },
          extras: {
            currentShopObj: currentShopObj,
            type: 1
          }
        })
      })
      //加
      $('.goods-list').on('tap', '.sure-choose-btn', function (e) {
        var goodsId = this.getAttribute('data-id')
        var index = this.getAttribute('index')
        var goodsBox = doc.getElementsByClassName("goods-op-box")
        goodsBox[index].innerHTML = '<img class="choose-icon" src="../images/choose.png" alt="" />\
                  <button type="button" class="cancel-choose-btn mui-btn mui-btn-danger choose-btn " index="' + index + '" data-id="' + goodsId + '">取消选择</button>'
        if (getType === 1) {
          pageList[index].isChoose = true
          applyGoods.applyGoodsList.push({
            goodsName: pageList[index].wareGoods.name,
            goodsId: pageList[index].wareGoods.wareGoodsId,
            amount: 1,
            wareHouseGoodsAmount: pageList[index].wareGoodsAmount,
            shopAmount: pageList[index].shopGoodsAmount.amount,
            cutImg: pageList[index].wareGoods.cutImg,
            tags: pageList[index].tags,
            typeFullName: pageList[index].typeFullName,
            score: pageList[index].wareGoods.score
          })
        } else {
          storePageList[index].isChoose = true
          applyGoods.applyGoodsList.push({
            goodsName: storePageList[index].wareGoods.name,
            goodsId: storePageList[index].wareGoods.wareGoodsId,
            amount: 1,
            wareHouseGoodsAmount: storePageList[index].wareGoodsAmount,
            shopAmount: storePageList[index].shopGoodsAmount.amount,
            cutImg: storePageList[index].wareGoods.cutImg,
            tags: storePageList[index].tags,
            typeFullName: storePageList[index].typeFullName,
            score: storePageList[index].wareGoods.score
          })
        }
      })
      //减
      $('.goods-list').on('tap', '.cancel-choose-btn', function () {
        var goodsId1 = this.getAttribute('data-id')
        var index1 = this.getAttribute('index')
        var goodsBox = doc.getElementsByClassName("goods-op-box")
        goodsBox[index1].innerHTML = '<div class="sure-choose-btn mui-btn mui-btn-primary choose-btn " index="' + index1 + '" data-id="' + goodsId1 + '">选择</div>'
        if (getType === 1) {
          pageList[index1].isChoose = false
        } else {
          storePageList[index1].isChoose = false
        }
        for (var s = 0; s < applyGoods.applyGoodsList.length; s++) {
          if (getType === 1 && applyGoods.applyGoodsList[s].goodsId * 1 === goodsId1 * 1) {
            applyGoods.applyGoodsList.splice(s, 1)
          } else if (getType === 2 && applyGoods.applyGoodsList[s].goodsId * 1 === goodsId1 * 1) {
            applyGoods.applyGoodsList.splice(s, 1)
          }
        }
        //        applyGoods.applyGoodsList.forEach(function(item, index0) {
        //        	console.log(item.goodsId)
        //          if(getType === 1 && item.goodsId === goodsId1) {
        //            applyGoods.applyGoodsList.splice(index0, 1)
        //          } else if(getType === 2 && item.goodsId === goodsId1) {
        //            applyGoods.applyGoodsList.splice(index0, 1)
        //          }
        //        })
      })

      $('.add-goods-type').on('tap', '#radioOld', function () {
        // console.log('old')
        getType = 1
        getGoods(params)
        mui('.total-scroll-wrapper').scroll().scrollTo(0, 0, 100);
        document.querySelector("#radioNew").className = 'redioNo'
        document.querySelector("#radioOld").className = 'redioYes'
      });
      $('.add-goods-type').on('tap', '#radioNew', function () {
        getType = 2
        getGoods(storeParams)
        mui('.total-scroll-wrapper').scroll().scrollTo(0, 0, 100);
        document.querySelector("#radioNew").className = 'redioYes'
        document.querySelector("#radioOld").className = 'redioNo'
      });
      //		下一步
      $('.btn-box').on('tap', '.next-btn', function () {
        if (applyGoods.applyGoodsList.length > 0) {
          config.ajax({
            type: "post",
            url: config.basePath + "/apply/writeDraft",
            async: true,
            data: applyGoods,
            headers: {
              'Content-Type': 'application/json'
            },
            success: function (res) {
              if (res.result === 1) {
                var titleText = currentShopObj.storeName + '-进货'
                if (!applyId) {
                  applyId = res.applyId
                }
                $.openWindow({
                  url: 'purchase2.html',
                  id: 'purchase2',
                  styles: {
                    top: 0, //新页面顶部位置
                    bottom: 0, //新页面底部位置
                    titleNView: {
                      titleText: titleText,
                      titleColor: "#FFFFFF",
                      titleSize: "17px",
                      backgroundColor: "#FF6800",
                      autoBackButton: true,
                      buttons: [{
                        float: "right",
                        fontSize: "18px",
                        fontSrc: "_www/fonts/iconfont.ttf", //wap2app内置字体文件
                        text: "\ue602",
                        onclick: function () {
                          var allPage = plus.webview.all()
                          var nowPage = plus.webview.getWebviewById('index')
                          for (var i = 0; i < allPage.length; i++) {
                            if (allPage[i].getURL() !== nowPage.getURL()) {
                              plus.webview.close(allPage[i]);
                            }
                          }
                        }
                      }],
                      splitLine: {
                        color: "#CCCCCC",
                        height: "1px"
                      }
                    }
                  },
                  extras: {
                    currentShopObj: currentShopObj,
                    applyGoodsList: applyGoods.applyGoodsList,
                    applyId: applyId,
                    tags: tags,
                    types: types,
                  },
                })
              }
            }
          });
        } else {
          $.toast('请选择货品');
        }
      })
    }

    function setTypesSelect() {
      var typePicker = new $.PopPicker({
        layer: 2
      });
      typePicker.setData(types);
      var typeCheck = doc.querySelector("#selsct-type")
      typeCheck.addEventListener('tap', function (event) {
        typePicker.show(function (items) {
          if (items[1].text) {
            typeCheck.innerText = '' + items[0].text + "/" + items[1].text;
            params.type = items[1].value
            storeParams.type = items[1].value
          } else {
            typeCheck.innerText = '' + items[0].text
            params.type = ''
            storeParams.type = ''
          }
          //返回 false 可以阻止选择框的关闭
          //return false;
        });
      }, false)
    }

    function setTagsSelect() {
      var tagPicker = new $.PopPicker();
      tagPicker.setData(tags)
      var tagCheck = doc.querySelector('#select-tag')
      tagCheck.addEventListener('tap', function (event) {
        tagPicker.show(function (items) {
          tagCheck.innerHTML = "<span>" + items[0].text + "</span>"
          params.tagIds = storeParams.tagIds = []
          if (items[0].value) {
            params.tagIds.push(items[0].value)
            storeParams.tagIds.push(items[0].value)
          }
        })
      })
    }

    function getTypes() {
      config.ajax({
        type: "get",
        url: config.basePath + "/goodsType/get.do",
        async: true,
        success: function (res) {
          if (res.result === 1) {
            res.data.forEach(function (item) {
              var obj = {}
              obj.value = item.id
              obj.text = item.name
              var children = []
              if (item.children.length > 0) {
                item.children.forEach(function (item1) {
                  var obj1 = {}
                  obj1.value = item1.id
                  obj1.text = item1.name
                  children.push(obj1)
                })
              }
              obj.children = children
              types.push(obj)
            })
            setTimeout(function () {
              setTypesSelect()
            }, 0)
          }
        }
      });

    }

    function getTag() {
      config.ajax({
        type: 'post',
        url: config.basePath + '/tag/get.do',
        data: {
          tagDescribe: ''
        },
        headers: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          if (res.result === 1) {
            res.tags.forEach(function (item) {
              var obj = {}
              obj.value = item.tagId
              obj.text = item.tagDescribe
              tags.push(obj)
            })
            setTimeout(function () {
              setTagsSelect()
            }, 0)
          }
        }
      })

    }

    function getGoods(param) {
      if (getType === 1) {
        if (pageList.length > 0) {
          setPage(pageList)
        } else {
          ajaxGoods(param)
        }
      } else if (getType === 2) {
        if (storePageList.length > 0) {
          setPage(storePageList)
        } else {
          ajaxGoods(param)
        }
      }
    }

    function ajaxGoods(param) {
      isLoading = true
      setLoading(1)
      console.log('ajaxGoods')
      console.log(JSON.stringify(param))
      config.ajax({
        type: "post",
        url: config.basePath + "/shopGoods/checkLike",
        async: true,
        data: param,
        headers: {
          'Content-Type': 'application/json'
        },
        success: function (res) {
          console.log(JSON.stringify(res))
          if (res.result === 1) {
            if (getType === 1) {
              pageTatol1 = res.pageList.pageTatol
              for (var k = 0; k < res.pageList.data.length; k++) {
                pageList.push(res.pageList.data[k])
              }
              setPage(pageList)
            } else {
              pageTatol2 = res.pageList.pageTatol
              console.log(JSON.stringify(res.pageList))
              for (var j = 0; j < res.pageList.data.length; j++) {
                storePageList.push(res.pageList.data[j])
              }
              setPage(storePageList)
            }
            isLoading = false
            setLoading(0)
          } else {
            isLoading = false
            setLoading(0)
          }
        }
      });
    }

    //页面
    function setPage(goodsList) {
      if (getType === 1) {
        for (var j = 0; j < pageList.length; j++) {
          var ifEqual = false
          for (var p = 0; p < applyGoods.applyGoodsList.length; p++) {
            if (pageList[j].wareGoods.wareGoodsId * 1 === applyGoods.applyGoodsList[p].goodsId * 1) {
              pageList[j].isChoose = true
              ifEqual = true
              break
            }
          }
          if (!ifEqual) {
            pageList[j].isChoose = false
          }
        }
      } else {
        for (var k = 0; k < storePageList.length; k++) {
          var ifEqual2 = false
          for (var p = 0; p < applyGoods.applyGoodsList.length; p++) {
            if (storePageList[k].wareGoods.wareGoodsId * 1 === applyGoods.applyGoodsList[p].goodsId * 1) {
              storePageList[k].isChoose = true
              ifEqual2 = true
              break
            }
          }
          if (!ifEqual2) {
            storePageList[k].isChoose = false
          }
        }
      }
      var html = template('goodsLi', {
        list: goodsList,
        imgPath: config.imgPath
      })
      $('.goods-list')[0].innerHTML = html
    }
  }(mui, document))
</script>

</html>